<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>类目编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style type="text/css">
        .uploadImg{
            border: none;
            width: 150px;
            display: block;
            margin-top: 10px;
        }
    </style>
</head>
<body>

<form class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">

    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" name="acc_sort" lay-verify="number" value="{$categoryInfo['acc_sort']}" placeholder="序号越小，排序越靠前" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分类名称</label>
        <div class="layui-input-block">
            <input  name="acc_name" lay-verify="required" placeholder="请输入分类名称" value="{$categoryInfo['acc_name']}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分类图标</label>
        <div class="layui-input-block">
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="upload">上传图片</button>
                {if $categoryInfo['acc_thumb']!=""}
                <img  id="demo1" class="uploadImg" src="{$categoryInfo['acc_thumb']}">
                <input type="hidden" name="acc_thumb" id="acc_thumb" src="{$categoryInfo['acc_thumb']}">
                {else/}
                <img  id="demo1" class="uploadImg">
                <input type="hidden" name="acc_thumb" id="acc_thumb">
                {/if}
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">跳转链接</label>
        <div class="layui-input-block">
            <input type="text" name="acc_url"  placeholder="请输入分类跳转链接" value="{$categoryInfo['acc_url']}" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">分类状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-filter="switch" name="acc_status" {if $categoryInfo['acc_status']==$Status['on']}checked{/if} lay-skin="switch" lay-text="启用|关闭">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <button class="layui-btn" lay-submit lay-filter="category-edit" id="category-edit">提交</button>
    </div>
</form>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form',"upload"], function(){
        var $ = layui.$
            ,form = layui.form
            ,upload=layui.upload;
        var uploadInst = upload.render({
            elem: '#upload'
            ,url: "{:url('admin/article/uploadImg')}"
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                var src=res.data.src;
                $("#acc_thumb").val(src);
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    })
</script>
</body>
</html>
